﻿using System;
using System.Globalization;
using System.Windows.Data;
using Labthink.PCSoft.UniversalHost4.Utility;

namespace Labthink.PCSoft.UniversalHost4.Instrument.Converters
{
    [ValueConversion(typeof(int), typeof(bool))]
    public class RadioValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
            return false;
            
            return value.ToInt() == parameter.ToInt();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
            return null;
            bool usevalue = (bool)value;
            if (usevalue)
            return parameter.ToInt();
            return null;
        }
    }
}
